Skip to content

Implement initial PyAutoBrain Bug Agent#20

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/bug-agent
Jul 8, 2026
Merged

Implement initial PyAutoBrain Bug Agent#20
Jammy2211 merged 2 commits into
mainfrom
feature/bug-agent

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Summary

Implements the initial PyAutoBrain Bug Agent — a new conductor at
agents/conductors/bug/ framed as the organism's immune system (organism-facing
name: Immune Agent). It recognises a pathogen (a bug, regression, failing test or
PyAutoHeart finding), tells it from benign self, classifies it, recalls prior cases
from PyAutoMemory, decides where the fix belongs, and emits a BugDecision the
existing start_dev → ship_* workflow consumes. It reasons; it never edits source.

It mirrors the Feature Agent, consults the read-only vitals faculty
(--check-health) and never queries Heart directly, and encodes a "no autoimmunity"
principle: user-facing workspace scripts are documentation, so a fix must prefer a
general library-source change over degrading a script (no injected test env-vars,
hard-coded paths, os.environ mutation, or silent guards).

Closes #18.

What's new

  • agents/conductors/bug/AGENTS.md — Tier: conductor; immune-system opening; four
    modes; the "no autoimmunity" fundamental principle; the BugDecision schema; the
    Health-conductor seam; the future diagnosis-faculty seam; hard boundaries.
  • agents/conductors/bug/BUG_TAXONOMY.md — classification (severity/scope/type/
    confidence), the fix-locus rules, the two health inputs, difficulty reuse.
  • agents/conductors/bug/_bug.py — reasoning core; imports _feature.py
    (no fork) and adds classify / reproduction / fix_locus / health_mode;
    stdlib-only, offline, never writes.
  • agents/conductors/bug/bug.sh — entrypoint; --check-health + a health
    subcommand (live vitals verdict + gh scan of filed PyAutoHeart issues).

Command-surface promotion

/bug moves from a work-type entry to a real conductor: registered in
bin/pyauto-brain; skills/bug/bug.md rewritten; /bug relocated into the
real-conductors tier across skills/COMMANDS.md, README.md, AGENTS.md.

Design decisions (agreed before implementation)

  • Conductor only, consulting the existing vitals faculty, with a documented seam
    for a future read-only diagnosis faculty (kept small, like Release-as-a-mode-of-Build).
  • Boundary with the Health conductor: Health drives the loop to GREEN (validation +
    recommend); the Bug Agent is the deferred edit-in-fix arm it hands a real code failure.
  • Two health inputs: the live vitals verdict AND filed PyAutoHeart GitHub issues
    (gh issue list --repo PyAutoLabs/PyAutoHeart), routed to PyAutoMind/bug/health_fixes/.

API Changes

None — PyAutoBrain is the Brain (reasoning layer), not a consumed PyPI library, so
there is no downstream workspace/API impact. This adds a new pyauto-brain bug
conductor and promotes the /bug command; no existing agent or command behaviour
changes. See full details below.

Test Plan

No repo unit-test suite exists for the Brain agents; validation is the CLI-mode
contract (mirroring how the Feature Agent is exercised). All verified on this branch:

Full details (for automation & release notes)

Added

  • pyauto-brain bug conductor with modes: specific · selection ·
    difficulty-constrained (--difficulty/--model/--budget/--ambitious/--impact) ·
    health. Flags: --check-health, --json. Env: $PYAUTO_HEART_REPO overrides the
    PyAutoHeart issues repo.
  • BugDecision fields: classification{severity,scope,type,confidence}, likely_owner,
    reproduction, memory_context, fix_locus{locus,note}, fix_strategy,
    recommended_workflow, rehome_suggestion, difficulty(+score/factors),
    health_validation, risks, next_action.

Changed (command surface)

  • /bug promoted work-type-entry → real conductor in bin/pyauto-brain,
    skills/bug/bug.md, skills/COMMANDS.md, README.md, AGENTS.md.

Notes

🤖 Generated with Claude Code

Add agents/conductors/bug/ — a new PyAutoBrain conductor framed as the organism's
immune system: recognise a bug / regression / failing test / PyAutoHeart finding,
tell it from benign self, classify it (severity/scope/type/confidence), decide
where the fix belongs (source-first; never degrade a user-facing workspace script,
the autoimmune failure mode), and emit a BugDecision the start_dev -> ship_*
workflow consumes. It reasons; it never edits source.

- _bug.py reuses the Feature Agent core (parse_prompt / estimate_difficulty /
  memory_context / in-flight down-ranking) and adds classify / reproduction /
  fix_locus / health_mode; stdlib-only, offline, never writes.
- bug.sh entrypoint; health mode reads the live vitals verdict AND scans filed
  PyAutoHeart issues (gh), routing real defects to bug/health_fixes/.
- Consults the vitals faculty, never Heart directly; conductor-only with a
  documented seam for a future read-only diagnosis faculty.
- Promote /bug from a work-type entry to a real conductor across bin/pyauto-brain,
  skills/bug/bug.md, skills/COMMANDS.md, README.md, AGENTS.md.

Refs #18

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an initial Bug Agent as a new PyAutoBrain conductor (agents/conductors/bug/) and promotes /bug from a work-type routing entry to a first-class command that emits a structured BugDecision for the existing start_dev → ship_* workflow.

Changes:

  • Add the Bug Agent conductor (docs, taxonomy, bash entrypoint, and deterministic Python analysis core).
  • Register pyauto-brain bug and promote /bug across the command surface docs.
  • Reuse Feature Agent deterministic helpers via import to avoid forking shared logic.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
skills/COMMANDS.md Promotes /bug into the real-conductors table and removes it from work-type entries.
skills/bug/bug.md Updates /bug user-facing instructions to call the Bug Agent conductor.
README.md Documents the new Bug Agent conductor in the repo overview and command taxonomy.
bin/pyauto-brain Registers the bug agent script/description and includes it in conductor ordering.
agents/conductors/bug/bug.sh Adds the Bug Agent deterministic entrypoint (modes, flags, vitals + Heart-issues scan).
agents/conductors/bug/BUG_TAXONOMY.md Defines bug classification/fix-locus taxonomy and health-input semantics for the agent.
agents/conductors/bug/AGENTS.md Adds the Bug Agent conductor documentation and BugDecision schema narrative.
agents/conductors/bug/_bug.py Implements prompt discovery/selection, bug classification, fix locus/strategy, and decision emission.
AGENTS.md Documents the Bug Agent among conductors and updates the command routing table accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread agents/conductors/bug/bug.sh Outdated
forward=()
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) sed -n '2,40p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;;
Comment on lines +76 to +94
if [[ "${forward[0]}" == "health" ]]; then
echo "== bug agent: health-issue mode =="
verdict="$(consult_vitals_verdict)"
echo " live vitals verdict: $verdict"
issues_json="$(mktemp)"
trap 'rm -f "$issues_json"' EXIT
if command -v gh >/dev/null 2>&1; then
echo " scanning filed PyAutoHeart issues: https://github.com/$HEART_ISSUES_REPO/issues"
gh issue list --repo "$HEART_ISSUES_REPO" --state open --limit 50 \
--json number,title,labels,url > "$issues_json" 2>/dev/null \
|| echo "[]" > "$issues_json"
else
echo " (gh not available — skipping the filed-issue scan)"
echo "[]" > "$issues_json"
fi
echo
exec python3 "$HERE/_bug.py" --mind "$mind" --memory "$memory" \
"${json_flag[@]}" health --verdict "$verdict" --heart-issues "$issues_json"
fi

# Optionally annotate a specific/selection decision with the vitals verdict
# (society-of-agents). This does not gate the decision — it informs it.
if [[ "$check_health" -eq 1 ]]; then
Comment on lines +282 to +294
prompts = [p for p in discover_bugs(mind) if p.name.lower() != "readme.md"]
in_flight = F._referenced_paths(mind, "active.md", "planned.md")
rows = []
for path in prompts:
p = F.parse_prompt(path, mind)
level, score, factors = F.estimate_difficulty(p)
cls = classify(p, factors)
rows.append({
"path": p["path"], "difficulty": level, "score": score,
"severity": cls["severity"], "type": cls["type"],
"in_flight": (p["path"] in in_flight) or ("bug/" + p["path"] in in_flight),
"factors": factors,
})
Comment thread agents/conductors/bug/_bug.py Outdated
Comment on lines +96 to +104
# scope — from the repo blast radius (single-file only when one repo + one @file).
n = factors["repos_affected"]
if n >= 3:
scope = "ecosystem"
elif n == 2:
scope = "multi-repo"
else:
scope = "single-repo"

Comment thread agents/conductors/bug/_bug.py Outdated
Comment on lines +360 to +361
print(f"Filed PyAutoHeart issues ({len(issues)} open) — classify each real-bug / "
"flaky / config / expected, then route:")
Comment thread agents/conductors/bug/AGENTS.md Outdated
Comment on lines +70 to +73
The bug can come from PyAutoHeart. `bug.sh health` gathers both signals and hands them
to `_bug.py`, which classifies each finding **real-bug / flaky / config / expected** and
decides whether the fix belongs in the affected repo, PyAutoHeart, PyAutoBuild or
PyAutoBrain:
Comment thread agents/conductors/bug/BUG_TAXONOMY.md Outdated
Comment on lines +79 to +84
For each finding the agent decides **real-bug / flaky / config / expected** and where the
fix belongs (affected repo, PyAutoHeart, PyAutoBuild, PyAutoBrain). Real defects become
`PyAutoMind/bug/health_fixes/<name>.md` prompts and enter the normal workflow; flaky /
expected findings are left to the Health conductor's loop. Validation after patching is
always the vitals faculty (`pyauto-heart readiness` GREEN/YELLOW), never a check re-run
here.
Comment thread agents/conductors/bug/_bug.py Outdated
Comment on lines +211 to +212
def health_validation(workflow: str, factors: dict) -> str:
"""Which health signals must be GREEN (via the vitals faculty) before shipping."""
Comment thread skills/bug/bug.md Outdated
Comment on lines +14 to +16
2. **From PyAutoHeart** — run `bin/pyauto-brain bug health`: it reads the live vitals
verdict **and** scans the filed PyAutoHeart issues, routing real defects to
`PyAutoMind/bug/health_fixes/`.
- bug.sh: route health / --check-health diagnostics to stderr so --json emits
  valid JSON on stdout; run (not exec) _bug.py in health mode so the EXIT trap
  cleans up the mktemp file; filter --help to comment lines only (no bash code).
- _bug.py: add bug-path-aware in-flight scan (_feature._referenced_paths only
  matched feature/… paths, so bug prompts were never down-ranked); emit single-file
  scope when ≤1 repo references exactly one file; extend re_home_check to docs and
  research; add a per-Heart-issue category hint (health mode + --json) so the code
  matches the docs; align health_validation docstring with the GREEN/YELLOW policy.
- docs: reword health-mode text in AGENTS.md / BUG_TAXONOMY.md / skills/bug/bug.md
  from "classifies + routes" to "hints a category; the reasoning layer confirms +
  routes"; fix the signal-discipline note (docstring is a kept specific marker).

Refs #18

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Jammy2211

Copy link
Copy Markdown
Contributor Author

Thanks — addressed all 13 Copilot comments in 65a70ce.

Correctness

  • bug.sh health / --check-health: diagnostics now go to stderr so --json emits valid JSON on stdout; health mode runs (not execs) _bug.py so the EXIT trap cleans up the mktemp file. (bug.sh:94, :98)
  • _bug.py in-flight down-ranking: added a bug/…-aware _referenced_bug_paths_feature._referenced_paths only matched feature/…, so bug prompts were never down-ranked. (_bug.py:294)

Spec/enum completeness

  • scope now emits single-file when ≤1 repo references exactly one file. (_bug.py:104)
  • re_home_check now covers docs and research, not just feature/refactor (guarded so a real defect signal keeps it a bug). (_bug.py:232)

Doc/code honesty

  • Health mode now emits a real per-issue category hint (real-bug / config / flaky / expected, from title+labels), in both human and --json output; docs in AGENTS.md / BUG_TAXONOMY.md / skills/bug/bug.md reworded from "classifies + routes" to "hints a category; the reasoning layer confirms + routes". (_bug.py:361, AGENTS:73, TAXONOMY:84, bug.md:16)
  • Signal-discipline note fixed: docstring is a kept specific marker, not an omitted generic word. (_bug.py:43, TAXONOMY:26)
  • health_validation docstring aligned with the GREEN/acknowledged-YELLOW ship policy. (_bug.py:212)
  • --help filters to comment lines only — no more set -uo pipefail / HERE= leakage. (bug.sh:50)

All CLI modes re-verified (JSON purity, single-file scope, per-issue hints, temp cleanup); line-count guard passes.

@Jammy2211 Jammy2211 merged commit 6dcca99 into main Jul 8, 2026
@Jammy2211 Jammy2211 deleted the feature/bug-agent branch July 8, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(pyautobrain): initial Bug Agent (immune-system conductor)

2 participants